/*
 * Copyright 2002-2015 the Beijing Brain Technology co.,LTD http://www.bris.cn/
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bris.niosocket.message.custom;

import java.util.concurrent.atomic.AtomicInteger;

import com.bris.niosocket.message.SerialNumber;
import com.bris.niosocket.message.util.CodeUtil;

/**
 * 定义民生银行流水规则</br>
 * 2015年11月27日</br>
 * @author xunaidong
 * @since 1.0.0
 */
public class CmbcSeriaNumber extends SerialNumber {
	
	/** 
	 * 指定外部流水号
	 * @param number 
	 * 
	 */ 
	public CmbcSeriaNumber(String number) {
		super(number);
	}
	
	public CmbcSeriaNumber(){
		
	}

	private static final int CMBC_SERIANUMBER_LENGTH = 32;
	
	private final static AtomicInteger sequence = new AtomicInteger(10000000);
	
	private final static String NUMBER_PREFIX = "3500000000";
	
	/* (non-Javadoc)
	 * @see com.cmbc.cspclient.socket.message.ISerialNumber#length()
	 */
	@Override
	public int length() {
		return CMBC_SERIANUMBER_LENGTH;
	}

	/* (non-Javadoc)
	 * @see com.cmbc.cspclient.message.SerialNumber#generate()
	 */
	@Override
	protected void generate() {
		number =  NUMBER_PREFIX+CodeUtil.getHexStr(CodeUtil.getByte(String.valueOf(System.currentTimeMillis()))) + String.valueOf(sequence.getAndIncrement());
	}


}
